package org.forwhat.dao.Impl;

import org.forwhat.bean.WhatTag;
import org.forwhat.dao.WhatTagDao;
import org.forwhat.framework.annotation.Data;
import org.forwhat.framework.annotation.InsertBean;

import java.util.List;

/**
 * @projectName: ForWhat
 * @package: org.forwhat.dao.Impl
 * @className: WhatTagDaoImpl
 * @author: LGJ
 * @description: TODO
 * @date: 2023/11/24 21:59
 * @version: 1.0
 */
//@Data("WhatTagDaoImpl")
public class WhatTagDaoImpl implements WhatTagDao {

    @InsertBean("BaseDaoImpl")
    private BaseDaoImpl baseDaoImpl;
    public BaseDaoImpl getBaseDaoImpl() {
        return baseDaoImpl;
    }

    public void setBaseDaoImpl(BaseDaoImpl baseDaoImpl) {
        this.baseDaoImpl = baseDaoImpl;
    }
    @Override
    public List<WhatTag> selectTagsByPostId(String postId) {
        try {
            return baseDaoImpl.selectList("select * from what_tag inner join what_post_tag on what_tag.tag_title = what_post_tag.tag_title where what_post_tag.post_id = ?"
                    , WhatTag.class, postId);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public int insertTag(WhatTag whatTag) {
        return baseDaoImpl.update("insert into what_tag(tag_title, tag_content, tag_create_time) value (?,?,?)", whatTag.getTagTitle(), whatTag.getTagContent(), whatTag.getTagCreateTime());
    }

    @Override
    public WhatTag selectTagByTitle(String title) {
        try {
            return baseDaoImpl.selectBean("select * from what_tag where tag_title = ?", WhatTag.class, title);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
